@include('admin.layout.bone_header')

<div class="layui-form layui-form-pane search">

    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="text" id="phone_like" autocomplete="off" placeholder="请输入手机号" class="layui-input">
        </div>
        <label class="layui-form-label">邀请人ID</label>
        <div class="layui-input-inline">
            <input type="text" id="spread_id" autocomplete="off" placeholder="请输入邀请人ID" class="layui-input">
        </div>

        <button class="layui-btn" data-type="reload">搜索</button>

    </div>

    <div class="layui-form-item">

{{--        <label class="layui-form-label">会员ID</label>--}}
{{--        <div class="layui-input-inline">--}}
{{--            <input type="text" id="user_id" autocomplete="off" placeholder="请输入会员ID" class="layui-input">--}}
{{--        </div>--}}

{{--    </div>--}}
</div>

<table class="layui-hide" id="think-table" lay-filter="think-table"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="user_setting">加注站设置</a>
    <a class="layui-btn layui-btn-xs" lay-event="user_quxian">设置区县</a>
    <a class="layui-btn layui-btn-xs" lay-event="recharge">充值</a>
    <a class="layui-btn layui-btn-xs" lay-event="balance_zhu">加注站充值</a>
    {{--    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>--}}
</script>

<script>

    layui.use('table', function () {
        let table = layui.table;
        UI.getPageTable(table, "{{route('admin.users.users')}}", [
            {field: 'user_id', title: 'ID', width: 80, sort: true, fixed: 'left'}
            , {field: 'phone', title: ' 手机号'}
            , {field: 'nickname', title: ' 昵称'}
            , {field: 'balance', title: ' 余额'}
            , {field: 'oli_nums', title: ' 能源'}
            , {field: 'is_hexiao', title: '核销',templet:function (d){
                    if(d['is_hexiao']==1){
                        return "<span style='color: green'>开启</span>"
                    }else{
                        return "<span style='color: red'>关闭</span>"
                    }
                }}
            , {field: 'quxian_auth', title: ' 区县',templet:function (d){
                    if(d['quxian_auth']==1){
                        return "<span style='color: green'>开启</span>"
                    }else{
                        return "<span style='color: red'>关闭</span>"
                    }
                }}
            , {field: 'consumer_coupon', title: ' 现金积分'}
            , {field: 'vip_index', title: ' 会员类型',templet:function (d){
                    let status_str = ['普通用户','会员','创客','联创']
                    return status_str[d['vip_index']]
                }}

            ,{fixed: 'right',title:'操作', align:'center',width:310, toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
            {{--if(obj.event === 'edit'){--}}
            {{--    UI.openLayer("{{route('admin.olis.edit')}}?oli_id="+data['oli_id'],980);--}}
            {{--}--}}
            {{--else if(obj.event == 'del'){--}}
            {{--    UI.delete(data['goods_id'],function(res){--}}
            {{--        table.reload('think-table');--}}
            {{--    },"{{route('admin.goods.del')}}");--}}
            {{--}--}}

            if(obj.event === 'recharge') {
                layer.prompt({formType:0,title:"充值",value:10000},
                    function(value, index){
                        HttpUtils.post('{{route('admin.users.recharge')}}',{
                            money:value,
                            user_id:data['user_id']
                        },function (res){
                            if(res['code'] != 200){
                                Utils.errorToast(res['msg'])
                                return;
                            }
                            layer.close(index)
                            layui.table.reload("think-table");
                        });
                    });
            }
            if(obj.event === 'balance_zhu') {
                layer.prompt({formType:0,title:"充值",value:10000},
                    function(value, index){
                        HttpUtils.post('{{route('admin.users.balance_zhu')}}',{
                            money:value,
                            user_id:data['user_id']
                        },function (res){
                            if(res['code'] != 200){
                                Utils.errorToast(res['msg'])
                                return;
                            }
                            layer.close(index)
                            layui.table.reload("think-table");
                        });
                    });
            }
            if(obj.event === 'user_setting') {
                //let data = obj.data;
                UI.openLayer("{{route('admin.users.user_setting')}}?user_id="+data['user_id'],800,500);
            }
            if(obj.event === 'user_quxian') {
                //let data = obj.data;
                UI.openLayer("{{route('admin.users.user_quxian')}}?user_id="+data['user_id'],800,500);
            }
        });
        let $ = layui.$, active = {
            reload:function (){
                let phone_like = $('#phone_like');
                let spread_id = $('#spread_id');
                //执行重载
                table.reload('think-table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        'phone_like':phone_like.val(),
                        'spread_id':spread_id.val(),
                    }
                });
            }
        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
